package com.rules.admin.parser;

import com.gillion.grule.client.utils.Closure;
import com.gillion.grule.client.utils.Streams;
import com.rules.admin.expression.*;
import com.rules.admin.expression.value.StringValue;


public class LogExpressionVistor extends ExpressionVisitorAdapter {
   public void vistor(RuleExpression ruleExpression) {
      String message = "开始执行规则：{}";
      ExecuteExpression executeExpression = new ExecuteExpression("LoggerAppenderHolder", "log", new Expression[]{new StringValue(), new StringValue(ruleExpression.getRuleName())});
      ruleExpression.getDeduction().getExpressions().add(0, executeExpression);
      Streams.of(ruleExpression.getAttributes()).forEach(new Closure<Attribute>() {
         public void execute(Attribute attribute) {
            attribute.accept(LogExpressionVistor.this);
         }
      });
      Streams.of(ruleExpression.getFacts()).forEach(new Closure<Fact>() {
         public void execute(Fact fact) {
            fact.accept(LogExpressionVistor.this);
         }
      });
      ruleExpression.getDeduction().accept(this);
      super.vistor(ruleExpression);
   }
}
